package com.timoon.component.panel.grid.panel;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.timoon.component.panel.grid.GridService;
import com.timoon.component.panel.grid.actions.AddButton;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */
public class GridPanel extends Panel {

	public GridPanel(String id, IModel<?> model,GridService service) {
		// TODO Auto-generated constructor stub
		super(id, model);
		
		
		List<Map<String, Object>> data=service.getData();
		
		RepeatingView listView=new RepeatingView("list");
		this.add(listView);
		for(int i=0;i<data.size();i++){
			WebMarkupContainer item=new WebMarkupContainer(listView.newChildId());
			Map<String,Object> record=data.get(i);
			Iterator it=record.keySet().iterator();
			while(it.hasNext()){
				String key=(String) it.next();
				item.add(new Label(key,new Model<String>(record.get(key)!=null?record.get(key).toString():"")));
				listView.add(item);
			}
			listView.add(item);
		}
		
		ModalWindow window=new ModalWindow("wk_window");
		this.add(window);
		window.setTitle("fewa");
		window.setContent(new AddPanel(window.getContentId(),service,window));
		
		Form form=new Form("wk_form");
		this.add(form);
		form.add(new AddButton("wk_add_btn",service,window));
		
	}


}
